
"""添加错误时间"""
from time import sleep, time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

from config.config import HOST, DRIVER_PATH


#数据#
url=HOST
username="admin"
password="123456"
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
topic="生日快乐"
time="20010533"
#定位器#
btn_login_locator=(By.NAME,"submit")
custmer_locator=(By.LINK_TEXT,"客户")
caer_locator=(By.LINK_TEXT,"客户关怀")
add_care_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(1) > div > a")
table_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tbody")
topic_name_locator=(By.NAME,"subject")
customer_name_locator=(By.NAME,"customer_name")
select_customer_name_locator=(By.CSS_SELECTOR,"#datas > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)")
btn_ok1_locator=(By.CSS_SELECTOR,"body > div:nth-child(9) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span")
content_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > textarea")
contact_name_locator=(By.CSS_SELECTOR,"#contacts_name")
select_contact_name_locator=(By.CSS_SELECTOR,"#data2 > tr:nth-child(1) > td:nth-child(1) > input[type=radio]")
btn_ok2_locator=(By.XPATH,"/html/body/div[9]/div[3]/div/button[1]")
time_locator=(By.CSS_SELECTOR,"#care_time")
date_locator=(By.ID,"dpTodayInput")
select_care_locator=(By.XPATH,"/html/body/div[5]/div[2]/div/form/table/tbody/tr[4]/td[4]/select")
#创建浏览器#
service = Service(DRIVER_PATH+r"\chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.maximize_window()
#打开url#
driver.get(url)
#登录#
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(password)
driver.find_element(*btn_login_locator).click()
sleep(2)
#进入客户#
driver.find_element(*custmer_locator).click()
sleep(2)
#点击客户关怀#
driver.find_element(*caer_locator).click()
sleep(1)
#点击添加客户关怀#
driver.find_element(*add_care_locator).click()
sleep(1)

#输入标题名#
driver.find_element(*topic_name_locator).send_keys(topic)
sleep(1)
#选择当前时间#
driver.find_element(*time_locator).send_keys(time)
#点击保存#
js="document.getElementsByName('submit')[0].click()"
driver.execute_script(js)
sleep(2)
driver.quit()